class ImageInterpreter implements IInterpreter {
  
  PImage blobs;
  Detector bs;
  PVector []  edge  ; 
  int i;
  int blobsNumber;
  boolean hasFoundBlobs;
  
  camera_shapePhysics app;
  ArrayList<PVector[]> blobList;
  
  ImageInterpreter(camera_shapePhysics app_pointer) {
    app = app_pointer;
    blobList = new ArrayList<PVector[]>();
    bs = new Detector(app, 0, 0, 800, 600, 0);
    blobs = loadImage("map.jpg");
    //blobs = loadImage("map_diagonal.jpg");
    blobsNumber = 0;
    hasFoundBlobs = false;
  }
  
  void init() {
    //we look for black blobs so last param value is 0
    if(blobList.size() > 0)
      blobList.clear();
    blobsNumber = 0;
    hasFoundBlobs = false;
    app.image(blobs,0,0); 
  }
  
  void findBlobs() {
    int edgelen = 0;
    blobs.filter(THRESHOLD);
    bs.imageFindBlobs(blobs);
    bs.loadBlobsFeatures();
    
    //strokeWeight(2); 
    if(!hasFoundBlobs) {
      //For each blob
      blobsNumber = bs.getBlobsNumber();
      println("ImageInterpreter: found " + blobsNumber + " blobs");
      app.labelBlobs.setValue("ImageInterpreter: found " + blobsNumber + " blobs");
      for(int i = 0; i < bs.getBlobsNumber(); i++){
        //gets the edge's pixels coordinates  
         blobList.add(bs.getEdgePoints(i)); 
      }
    }
    
    
    if(blobsNumber>0)
      hasFoundBlobs = true;
  }
  
  boolean hasFoundBlobs(){
    return hasFoundBlobs;
  }
  
  ArrayList<PVector[]> getBlobList() {
    return blobList;
  }
  
}
